package com.tensquare.article.dao;

import com.tensquare.article.pojo.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author Alfred
 * @description  @Modifying 修改注解  只有自定义增删改时才使用
 * @date 2021/4/23 20:26
 */
public interface ArticleDao extends JpaRepository<Article,String>, JpaSpecificationExecutor<Article> {

    /**
     * fetch data by rule id
     *
     * @description  根据频道ID获取文章列表
     * @param
     * @return
     */
    @Query("select a from Article as a where a.channelid=?1")
    public Page<Article> findByChannelid(String channelid, Pageable pageable);

    /**
     * fetch data by rule id
     *
     * @description  根据专栏ID获取文章列表
     * @param
     * @return
     */
    @Query("select a from Article as a where a.columnid=?1")
    public Page<Article> findByColumnid(String columnid, Pageable pageable);

    /**
     * fetch data by rule id
     *
     * @description  审核
     * @param
     * @return
     */
    @Modifying
    @Query("update Article set state='1' where id=?1")
    public void examine(String id);

    /**
     * fetch data by rule id
     *
     * @description  点赞
     * @param
     * @return
     */
    @Modifying
    @Query("update Article set thumbup = thumbup+1 where id=?1")
    public int updateThumbup(String id);

    /**
     * fetch data by rule id
     *
     * @description  头条文章
     * @param
     * @return
     */
    @Query("select a from Article a where a.istop=?1")
    public List<Article> findArticlesByIstop(String istop);
}
